package com.baseframe.auth.service;

import com.baseframe.auth.constant.BaseAuthConstant;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.util.List;


//@AllArgsConstructor
public class BaseClientDetailsServiceImpl extends JdbcClientDetailsService {

//    private DataSource dataSource;
//
//    private PasswordEncoder passwordEncoder;

    public BaseClientDetailsServiceImpl(DataSource dataSource) {
        super(dataSource);
    }

//    @Override
//    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
//        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
//        BaseClientDetails baseClientDetails = jdbcTemplate.queryForObject(BaseAuthConstant.SELECT_CLIENT_SQL, new BeanPropertyRowMapper<>(BaseClientDetails.class), clientId);
//        if (baseClientDetails==null){
//            throw  new SecurityException("客户端不存在或者不可用~");
//        }
//        BaseClientDetails clientDetails = new BaseClientDetails();
//        clientDetails.setClientId(clientId);
//        clientDetails.setClientSecret(passwordEncoder.encode(baseClientDetails.getClientSecret()));
//
//
//        return clientDetails;
//    }
}
